import request from '@/utils/request'

let cateList

export function list(params) {
  return request({
    url: '/api/dashboard/v1/course',
    params
  })
}

export function detail(id) {
  return request({
    url: `/api/dashboard/v1/course/${id}`
  })
}

export function add(data) {
  return request({
    url: '/api/dashboard/v1/course',
    method: 'post',
    data
  })
}

export function update(data) {
  return request({
    url: `/api/dashboard/v1/course/${data.id}`,
    method: 'put',
    data
  })
}

export function change(data) {
  const url = !data.status
    ? `/api/dashboard/v1/course/${data.id}/resume`
    : `/api/dashboard/v1/course/${data.id}/forbid`
  return request({
    url,
    method: 'patch'
  })
}

export function remove(id) {
  return request({
    url: `/api/dashboard/v1/course/${id}`,
    method: 'delete'
  })
}

export async function cate() {
  if (cateList) return cateList
  const data = await request({
    url: '/api/dashboard/v1/course/cate'
  })
  cateList = data
  return data
}

export function place() {
  return request({
    url: '/api/dashboard/v1/course/place'
  })
}
